import { takeEvery, call, put } from "redux-saga/effects";

function* getTopics(action) {
    yield put({
        type: "topics_loading",
    });
    const res = yield call(
        fetch,
        `https://cnodejs.org/api/v1/topics?limit=10&page=${action.page}`
    );

    const data = yield res.json();
    yield put({
        type: "topics_update",
        data: data.data,
    });
}

function* watchTopics() {
    yield takeEvery("updateTopics", getTopics);
}

export default watchTopics;
